package org.fuys.coder.infrastructure.repository;

import org.fuys.coder.domain.rank.repository.IHotRankRepository;
import org.fuys.coder.domain.substance.model.vo.SubstanceVO;
import org.fuys.coder.infrastructure.util.RedisUtil;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * @projectName: fuys-low-coder
 * @package: org.fuys.coder.infrastructure.repository
 * @className: HotRankRepository
 * @author: WangJing
 * @description: 热门排行仓储实现类
 * @date: 2024/9/6 20:01
 * @version: 1.0
 */
@Service
public class HotRankRepository implements IHotRankRepository {

    @Resource
    private RedisUtil redisUtil;


    @Override
    public void putHotSubstance(String redisKey, List<SubstanceVO> k, List<Double> weights) {
        redisUtil.deleteKey(redisKey);
        redisUtil.zsetPutByPipeLine(redisKey,k,weights);
    }

    @Override
    public Set<ZSetOperations.TypedTuple<Object>> getHotSubstance(String redisKey, int count) {
        return redisUtil.zsetGetMembersAndScore(redisKey,count);
    }
}
